<?php session_start();
require_once($_SERVER["DOCUMENT_ROOT"] . '/Esquina_da_TI/gui/fachada.php');

$fachada = new fachada();

// Campo que fez requisição
$campo = $_GET['campo'];
// Valor do campo que fez requisição
$valor = $_GET['valor'];

if ($campo == "loginUsuario") {

    if ($valor == "") {
        echo "<input type=hidden name=validacaoLogin value=0>";
    }
    else if (strlen($valor)< 6 || strlen($valor)> 30) {
            echo "<img src='../images/false.png' width='16' height='16' alt='false'/>&nbsp;<font style='font-family:arial' color='red' size='1'>Seu login dever ter entre 6 e 30 caracteres!</font><input type=hidden name=validacaoLogin value=0>";
        }
        else if (!$fachada->validarLogin($valor)) {
                echo "<img src='../images/false.png' width='16' height='16' alt='false'/>&nbsp;<font style='font-family:arial' color='red' size='1'>Login Inválido</font><input type=hidden name=validacaoLogin value=0>";
            }
            else if(!$fachada->verificarLogin($valor)) {
                    echo "<img src='../images/false.png' width='16' height='16' alt='false'/>&nbsp;<font style='font-family:arial' color='red' size='1'>Login já cadastrado!</font><input type=hidden name=validacaoLogin value=0>";
                }
                else {
                    echo "<img src='../images/true.png' width='16' height='16' alt='true'/>&nbsp;<font style='font-family:arial' color='green' size='1'>Ok!</font><input type=hidden name=validacaoLogin value=1>";
                }
}

// Verificando o campo email
if ($campo == "email") {
    if($valor=="") {
        echo "<input type=hidden name=validacaoEmail value=0>";
    }
    else if (!$fachada->validarEmail($valor)) {
            echo "<img src='../images/false.png' width='16' height='16' alt='false'/>&nbsp;&nbsp;<font style='font-family:arial' color='red' size='1'>Email Inválido!</font><input type=hidden name=validacaoEmail value=0>";

        }
        else if(!$fachada->verificarEmail($valor)) {
                echo "<img src='../images/false.png' width='16' height='16' alt='false'/>&nbsp;&nbsp;<font style='font-family:arial' color='red' size='1'>Email já cadastrado!</font><input type=hidden name=validacaoEmail value=0>";
            }
            else {
                echo "<img src='../images/true.png' width='16' height='16' alt='true'/>&nbsp;<font style='font-family:arial' color='green' size='1'>Ok!</font><input type=hidden name=validacaoEmail value=1>";
            }
}
// verificando a imagem
if ($campo=="txtImagem") {

    $valorImagem = strtoupper($_SESSION["autenticaIMG"]);
    $img = strtoupper($valor);
    if ($valor == "") {
        echo "<input type=hidden name=validacaoTxtImagem value=0>";
    }
    else if ($valorImagem == $img) {
            echo "<img src='../images/true.png' width='16' height='16' alt='true'/>&nbsp;<font style='font-family:arial' color='green' size='1'>Ok!</font><input type=hidden name=validacaoTxtImagem value=1>";
        }
        else {
            echo "<img src='../images/false.png' width='16' height='16' alt='false'/>&nbsp;&nbsp;<font style='font-family:arial' color='red' size='1'>Caracteres Invalidos!</font><input type=hidden name=validacaoTxtImagem value=0>";
        }
}
if ($campo=="cpf") {

    if ($valor == "") {
        echo "<input type=hidden name=validacaoCpf value=0>";
    }
    else if (!$fachada->validarCpf($valor)) {
            echo "<img src='../images/false.png' width='16' height='16' alt='false'/>&nbsp;<font style='font-family:arial' color='red' size='1'>CPF Invalido!</font><input type=hidden name=validacaoCpf value=0>";
        }
        else if (!$fachada->verificarCpf($valor)) {
                echo "<img src='../images/false.png' width='16' height='16' alt='false'/>&nbsp;<font style='font-family:arial' color='red' size='1'>CPF já cadastrado!</font><input type=hidden name=validacaoCpf value=0>";
            }

            else {
                echo "<img src='../images/true.png' width='16' height='16' alt='true'/>&nbsp;<font style='font-family:arial' color='green' size='1'>Ok!</font><input type=hidden name=validacaoCpf value=1>";
            }
}
if ($campo=="cnpj") {
    if ($valor=="") {
        echo "<input type=hidden name=validacaoCnpj value=0>";
    }
    else if (!$fachada->validarCnpj($valor)) {
            echo "<img src='../images/false.png' width='16' height='16' alt='false'/>&nbsp;<font style='font-family:arial' color='red' size='1'>CNPJ Invalido!</font><input type=hidden name=validacaoCnpj value=0>";
        }
        else if (!$fachada->verificarCnpj($valor)) {
                echo "<img src='../images/false.png' width='16' height='16' alt='false'/>&nbsp;<font style='font-family:arial' color='red' size='1'>CNPJ já cadastrado!</font><input type=hidden name=validacaoCnpj value=0>";
            }

            else {
                echo "<img src='../images/true.png' width='16' height='16' alt='true'/>&nbsp;<font style='font-family:arial' color='green' size='1'>Ok!</font><input type=hidden name=validacaoCnpj value=1>";
            }
}
if ($campo=="razaoSocial") {
    if ($valor=="") {
        echo "<input type=hidden name=validacaoRazaoSocial value=0>";
    }
    else if (!$fachada->validarRazao($valor)) {
            echo "<img src='../images/false.png' width='16' height='16' alt='false'/>&nbsp;<font style='font-family:arial' color='red' size='1'>Razão Social Inválida!</font><input type=hidden name=validacaoRazaoSocial value=0>";
        }
        else if (!$fachada->verificarRazao($valor)) {
                echo "<img src='../images/false.png' width='16' height='16' alt='false'/>&nbsp;<font style='font-family:arial' color='red' size='1'>Razão Social já cadastrada!</font><input type=hidden name=validacaoRazaoSocial value=0>";
            }

            else {
                echo "<img src='../images/true.png' width='16' height='16' alt='true'/>&nbsp;<font style='font-family:arial' color='green' size='1'>Ok!</font><input type=hidden name=validacaoRazaoSocial value=1>";
            }
}
if ($campo=="posicao") {
  
    if ($valor =="20") {
        require_once('../DAO/Conexao.php');
        $conexao = new Conexao();
        $conexao->abrirConexao();
        $query = "select max(validade) from propaganda where posicao=20;";
        $r = $conexao->executarQuery($query);
        $linha = mysql_fetch_array($r);
        $data = $linha["max(validade)"];
        $s= explode('-', $data);
        $t= explode(' ',$s[2]);
        
        echo "<input type='Text' name='disponibilidade' id='disponibilidade' value='$t[0]/$s[1]/$s[0] $t[1]' size='17' readonly>";
        $conexao->fecharConexao();
    }
    else{
        
        require_once('../DAO/Conexao.php');
        $conexao = new Conexao();
        $conexao->abrirConexao();
        $query = "select max(validade) from propaganda where posicao=50;";
        $r = $conexao->executarQuery($query);
        $linha = mysql_fetch_array($r);
        $data = $linha["max(validade)"];
        $s= explode('-', $data);
        $t= explode(' ',$s[2]);

        echo "<input type='Text' name='disponibilidade' id='disponibilidade' value='$t[0]/$s[1]/$s[0] $t[1]' size='17' readonly>";
        $conexao->fecharConexao();
    }
}

if ($campo=="ativar") {

    if ($valor =="Ativar") {
    require_once($_SERVER["DOCUMENT_ROOT"] . '/Esquina_da_TI/Gui/Fachada.php');
require_once($_SERVER["DOCUMENT_ROOT"] . '/Esquina_da_TI/ClassesBasicas/Propaganda.php');
require_once($_SERVER["DOCUMENT_ROOT"] . '/Esquina_da_TI/ClassesBasicas/Usuario.php');
$fachada = new Fachada();
$banner = new Propaganda();
$usuario = new Usuario();
                            //$sql = mysql_query("select banner from Propaganda where posicao=50 and validade>".$data." ".$hora." and dataInicio<=".$data." ".$hora." and ativo=1;");
         $fachada->localizarUsuario($codigo, $nome, $login);
                            $cliente = $usuario->getCodUsuario();
        require_once('../DAO/Conexao.php');
        $conexao = new Conexao();
        $conexao->abrirConexao();
         $sql = $conexao->executarQuery("select codPropaganda, valor from Propaganda where cliente='$cliente' and ativo=0;");

                            $result = mysql_fetch_array($sql);
                            $codigo  = $result['codPropaganda'];
             $conexao->executarQuery("update propaganda set ativo=1 where codPropaganda='$codigo';");
       
        $conexao->fecharConexao();
    }
}
















?>
